/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       texturedmaterial.cpp
 * Author:     karooolek
 * Created on: 2009-03-14
 *
 **********************************************************************************************************************/

#include "texturedmaterial.h"

namespace mGameEngine
{
namespace Graphics
{

TexturedMaterial::TexturedMaterial(const Texture *texture,
        const Color &ambient, const Color &diffuse,
        const Color &specular, float shininess, const Color &emmisive) :
            StandardMaterial(ambient, diffuse, specular, shininess, emmisive),
            _texture(texture)
{
}

TexturedMaterial::~TexturedMaterial()
{
}

void TexturedMaterial::set() const
{
    // no texture, this is standard material
    if(!_texture)
    {
        return StandardMaterial::set();
    }

    // create and compile gpu program
    static GPUProgram gpuProgram(
#include "texturedmaterial.vert"
        ,
#include "texturedmaterial.frag"
        , true);

    // bind gpu program
    gpuProgram.use();

    // standard material settings
    glMaterialfv(GL_FRONT, GL_AMBIENT, _ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, _diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, _specular);
    glMaterialf(GL_FRONT, GL_SHININESS, _shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, _emissive);

    // texture
    gpuProgram.setTexture("texture", _texture, 0);
}

}
}

